package com.contory.ssn_lgnd.app;

import java.util.ArrayList;

import android.util.Log;

import com.contory.ssn_lgnd.framework.Music;
import com.contory.ssn_lgnd.framework.Sound;
import com.contory.ssn_lgnd.framework.gl.Animation;
import com.contory.ssn_lgnd.framework.gl.ESShader;
import com.contory.ssn_lgnd.framework.gl.ESShaderCodeImpoter;
import com.contory.ssn_lgnd.framework.gl.Font;
import com.contory.ssn_lgnd.framework.gl.FrameBufferObject;
import com.contory.ssn_lgnd.framework.gl.Texture;
import com.contory.ssn_lgnd.framework.gl.TexturePtr;
import com.contory.ssn_lgnd.framework.gl.TextureRegion;
import com.contory.ssn_lgnd.framework.impl.GLGame;

public class Assets {
	public static Texture tex1;
	public static Texture tex2;
	public static Font font;
	public static TextureRegion tex_reg_whiteTexel;
	public static TextureRegion tex_reg_sun;
	public static TextureRegion tex_reg_rock;
	public static TextureRegion tex_reg_button1;
	public static TextureRegion tex_reg_button2;
	public static TextureRegion tex_reg_mucisIcon;
	public static TextureRegion tex_reg_disable;
	public static TextureRegion tex_reg_effectIcon;
	public static TextureRegion tex_reg_player;
	public static TextureRegion tex_reg_cloud1;
	public static TextureRegion tex_reg_cloud2;
	public static TextureRegion tex_reg_controlerCircle;
	public static TextureRegion tex_reg_controlerArrow;
	public static TextureRegion tex_reg_enemy1;
	public static TextureRegion tex2_reg_whiteTexel;
	public static TextureRegion tex_reg_redBullet;
	public static TextureRegion TEX_REG_YELLOBULLET;
	public static TextureRegion TEX_REG_PURPLEBULLET;
	public static TextureRegion TEX_REG_CURSOR;
	public static TextureRegion tex_reg_swap;
	public static TextureRegion TEX_REG_TERRAIN_RECTTILE;
	public static TextureRegion TEX_REG_TERRAIN_TRIANGLE_TOPRIGHT;
	public static TextureRegion TEX_REG_TERRAIN_TRIANGLE_TOPLEFT;
	public static TextureRegion TEX_REG_TERRAIN_TRIANGLE_DOWNRIGHT;
	public static TextureRegion TEX_REG_TERRAIN_TRIANGLE_DOWNLEFT;
	public static TextureRegion TEX_REG_ENEMY_BULLET;
	public static TextureRegion TEX_REG_BUBBLE;
	public static TextureRegion TEX_REG_SMALL_EXPLOSION;
	public static TextureRegion TEX_REG_OPTION_BTR;
	public static TextureRegion TEX_REG_BOARD;
	public static Animation ANI_EXPLOSION; 
	public static TextureRegion TEX_REG_BG_ROCK;
	
	private static ArrayList<TexturePtr> reload_textures = new ArrayList<TexturePtr>();

	public static Music BGM;
	
	public static Sound sound_click;
	
	public static ESShaderCodeImpoter codeImporter;

	public static void load(GLGame game){
		tex1 = new Texture(game, "tex1.png");
		reload_textures.add(tex1);
		font = new Font(tex1.width, tex1.height, 1, 0, 16, 16, 20);
		tex_reg_whiteTexel = new TextureRegion(tex1.width, tex1.height, 0, 120, 10, 10);
		tex_reg_sun = new TextureRegion(tex1.width, tex1.height, 0, 252, 128, 64);
		tex_reg_rock = new TextureRegion(tex1.width, tex1.height, 0, 180, 48, 48);
		tex_reg_button1 = new TextureRegion(tex1.width, tex1.height, 0, 340, 80, 16);
		tex_reg_button2 = new TextureRegion(tex1.width, tex1.height, 0, 356, 16, 16);
		tex_reg_mucisIcon = new TextureRegion(tex1.width, tex1.height, 0, 372, 16, 16);
		tex_reg_disable = new TextureRegion(tex1.width, tex1.height, 0, 390, 16, 16);
		tex_reg_effectIcon = new TextureRegion(tex1.width, tex1.height, 0, 405, 16, 16);
		tex_reg_player = new TextureRegion(tex1.width, tex1.height, 0, 230, 32, 16);
		tex_reg_cloud1 = new TextureRegion(tex1.width, tex1.height, 0, 130, 14, 14);
		tex_reg_cloud2 = new TextureRegion(tex1.width, tex1.height, 20, 130, 24, 24);
		tex_reg_controlerCircle = new TextureRegion(tex1.width, tex1.height, 0, 420, 64, 64);
		tex_reg_controlerArrow = new TextureRegion(tex1.width, tex1.height, 80, 340, 16, 16);
		tex_reg_enemy1 = new TextureRegion(tex1.width, tex1.height, 80, 356, 32, 16);
		tex_reg_redBullet = new TextureRegion(tex1.width, tex1.height, 32, 230, 16, 8);
		TEX_REG_PURPLEBULLET = new TextureRegion(tex1.width, tex1.height, 48, 230, 16, 8);
		TEX_REG_YELLOBULLET = new TextureRegion(tex1.width, tex1.height, 32, 238, 16, 8);
		tex_reg_swap = new TextureRegion(tex1.width, tex1.height, 80, 420, 66, 66);
		TEX_REG_TERRAIN_RECTTILE = new TextureRegion(tex1.width, tex1.height, 51, 121, 64, 64);
		TEX_REG_TERRAIN_TRIANGLE_TOPLEFT = new TextureRegion(tex1.width, tex1.height, 116, 121, 64, 64);
		TEX_REG_TERRAIN_TRIANGLE_TOPRIGHT = new TextureRegion(tex1.width, tex1.height, 181, 121, 64, 64);
		TEX_REG_TERRAIN_TRIANGLE_DOWNLEFT = new TextureRegion(tex1.width, tex1.height, 246, 121, 64, 64);
		TEX_REG_TERRAIN_TRIANGLE_DOWNRIGHT = new TextureRegion(tex1.width, tex1.height, 116, 186, 64, 64);
		TEX_REG_BG_ROCK = new TextureRegion(tex1.width, tex1.height, 129, 251, 64, 127);
		TEX_REG_ENEMY_BULLET = new TextureRegion(tex1.width, tex1.height, 64, 230, 16, 16);
		TEX_REG_CURSOR = new TextureRegion(tex1.width, tex1.height, 80, 230, 16, 16);
		TEX_REG_SMALL_EXPLOSION = new TextureRegion(tex1.width, tex1.height, 50, 200, 30, 30);
		TEX_REG_BUBBLE = new TextureRegion(tex1.width, tex1.height, 48, 238, 8, 8);
		TEX_REG_OPTION_BTR = new TextureRegion(tex1.width, tex1.height, 20, 360, 16, 16);
		TEX_REG_BOARD = new TextureRegion(tex1.width, tex1.height, 260, 0, 64, 24);
		float offset = 64;
		float strX = 245f - 30f;
		float strY = 256f - 30f;
		ANI_EXPLOSION = new Animation(0.01f, 
				new TextureRegion(tex1.width, tex1.height, strX, 			  strY, 60, 60),
				new TextureRegion(tex1.width, tex1.height, strX + (1)*offset, strY, 60, 60),
				new TextureRegion(tex1.width, tex1.height, strX + (2)*offset, strY, 60, 60),
				new TextureRegion(tex1.width, tex1.height, strX + (3)*offset, strY, 60, 60),
				
				new TextureRegion(tex1.width, tex1.height, strX, 			  strY + (1)*offset, 60, 60),
				new TextureRegion(tex1.width, tex1.height, strX + (1)*offset, strY + (1)*offset, 60, 60),
				new TextureRegion(tex1.width, tex1.height, strX + (2)*offset, strY + (1)*offset, 60, 60),
				new TextureRegion(tex1.width, tex1.height, strX + (3)*offset, strY + (1)*offset, 60, 60),
				
				new TextureRegion(tex1.width, tex1.height, strX, 			  strY + (2)*offset, 60, 60),
				new TextureRegion(tex1.width, tex1.height, strX + (1)*offset, strY + (2)*offset, 60, 60),
				new TextureRegion(tex1.width, tex1.height, strX + (2)*offset, strY + (2)*offset, 60, 60),
				new TextureRegion(tex1.width, tex1.height, strX + (3)*offset, strY + (2)*offset, 60, 60),

				new TextureRegion(tex1.width, tex1.height, strX, 			  strY + (3)*offset, 60, 60),
				new TextureRegion(tex1.width, tex1.height, strX + (1)*offset, strY + (3)*offset, 60, 60),
				new TextureRegion(tex1.width, tex1.height, strX + (2)*offset, strY + (3)*offset, 60, 60),
				new TextureRegion(tex1.width, tex1.height, strX + (3)*offset, strY + (3)*offset, 60, 60));
		tex2 = new Texture(game, "tex2.png");
		reload_textures.add(tex2);
		tex2_reg_whiteTexel = new TextureRegion(tex2.width, tex2.height, 0, 0, 16, 16);
		
		sound_click = game.getAudio().newSound("ok.ogg");
		
		codeImporter = new ESShaderCodeImpoter(game.getFileIO());
		codeImporter.addShaderCode("shd_defualt_vertex.txt");
		codeImporter.addShaderCode("shd_default_fragment.txt");
		codeImporter.addShaderCode("shd_blur_fragment.txt");
		codeImporter.addShaderCode("shd_glow_fragment.txt");
		codeImporter.addShaderCode("shd_curtain_fragment.txt");
		codeImporter.addShaderCode("shd_circle_fragment.txt");
		codeImporter.addShaderCode("shd_grad_fragment.txt");
	}
	
	public static void reload(){
		for (TexturePtr trPtr_chd : reload_textures) {
			trPtr_chd.load();
		}
	}
	
	public static void playSound(Sound sound) {
        if(Settings.effectEnabled == 1)
            sound.play(1);
    }
	
	public static void musicReady(GLGame game, String musicName){
    	if(BGM != null)
    		BGM.dispose();
    	try{
    		BGM = game.getAudio().newMusic(musicName);
    	}
    	catch(Exception e){
    		BGM = null;
    		return;
    	}
    	BGM.setLooping(true);
    	BGM.setVolume(1);
    }
	
	public static void playBGM(Music music){
		if(Settings.musicEnabled == 1 && music != null)
			music.play();
	}
	
	public static void stopBGM(Music music){
		if(music != null)
			music.stop();
	}
}
